import os
from selenium import webdriver
from selenium.webdriver.chrome.service import Service


class Driver:
    driver = None
    filename = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    # 获取驱动
    def get_driver(self, url):
        if self.driver is None:
            driver_path = os.path.join(self.filename, "config", "chromedriver.exe")
            service = Service(driver_path)
            self.driver = webdriver.Chrome(service=service)
            self.driver.maximize_window()
            self.driver.get(url)
        return self.driver

    # 退出驱动
    def quit_driver(self):
        if self.driver is not None:
            self.driver.quit()
            self.driver = None
